﻿@using CoralNode.Core.Entity.Domains.Site    @using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Contexts
@using CoralNode.MvcClient.Helper
@model CoralNode.Core.Entity.Domains.Prototype.PrototypeDomain

@{
    ViewBag.Title = "Create";
    ViewData["curr"] = "field";
    IList<FieldPluginDomain> fieldPlugins = ViewBag.FieldTypeList;
}
@Html.IncludePage("CoralAdmin/prototype", "_Left", new { current = "prototype" })
<!--content-->
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">内容设计&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">原型管理</b></span>
        </div>
        <div id="main">
            @Html.IncludePage("CoralAdmin/Prototype", "_tab", new { prototypeId = Model.Id })
            <div class="content_tab extra_normal pl_26">
                <div class="tablist extra_normal js_field_tab">
                    @foreach (var item in @ViewBag.FieldGroupList) {
                        <a data-groupid="@item.Id">@item.Title</a>
                    }
                </div>
                <div class="fun">
                    <a href="#" class="btn_4" data-title="字段组管理" data-dialog=""
                        id="addTab">字段组管理</a>
                </div>
            </div>
            <div class="pt_3">
                <form id="spform" action="/m/prototype/settingField?prototypeId=@ViewBag.PrototypeId" method="POST">
                    @if (@ViewBag.Msg != null) {
                        <div class="error_msg">
                            @ViewBag.Msg.Msg
                        </div>
                    }
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    <div class="fieldContainer">
                        <div id="fieldManage" data-tabs="0" data-field="1">
                            <div class="js_tabcnt">
                                @foreach (var group in @ViewBag.FieldGroupList) {
                                    <div class="table_form form_main" data-groupid="@group.Id">
                                        <table>
                                            <tbody>
                                                @foreach (var item in group.FieldList) {
                                                    var extendField = fieldPlugins.FirstOrDefault(n => n.Id == item.FieldType & n.Type == PrototypeEnums.FieldPlugin.Extend);
                                                    <tr @(extendField != null ? "class=extend" : string.Empty) itemid="@item.Id" data-type="@item.FieldType">
                                                        <th width="60"><span class="info_txt">@item.Title：</span></th>
                                                        <td>
                                                            @if (@item.FieldType == NodeEnums.BasicFieldType.TextField) {
                                                                <input class="text w_37" type="text" readonly="readonly" value="@item.DefaultValue" />
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.TextArea) {
                                                                <textarea readonly="readonly" class="h_8 w_37">@item.DefaultValue</textarea>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.PasswordField) {
                                                                <input class="text w_37" type="password" readonly="readonly" value="@item.DefaultValue"/>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.RadioButton) {
                                                                foreach (var e in @item.EntryList) {
                                                                    if (@e.EntryValue == @item.DefaultValue) {
                                                                <label class="mr_2">
                                                                    <input class="radio" checked="checked" readonly="readonly" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                                    } else {
                                                                <label class="mr_2">
                                                                    <input class="radio" readonly="readonly" type="radio" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                                    }
                                                                }
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.CheckBox) {
                                                                foreach (var e in @item.EntryList) {
                                                                    if (@ManageHtmlHelper.Contains(@item.DefaultValue, @e.EntryValue)) {
                                                                <label class="mr_2">
                                                                    <input class="checkbox" readonly="readonly" checked="checked" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                                    } else {
                                                                <label class="mr_2">
                                                                    <input class="checkbox" readonly="readonly" type="checkbox" value="@e.EntryValue"><span>@e.EntryName</span></label>
                                                                    }
                                                                }

                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.SelectBox) {
                                                                <select style="width: 382px" readonly="readonly">
                                                                    @foreach (var e in @item.EntryList) {
                                                                        if (@e.EntryValue == @item.DefaultValue) {
                                                                        <option selected="selected">@e.EntryName</option>
                                                                        } else {
                                                                        <option>@e.EntryName</option>
                                                                        }
                                                                    }

                                                                </select>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.FileField) {
                                                                <div class="field_file"></div>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiFile) {
                                                                <div class="field_file"></div>
                                                                <div class="field_file"></div>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.ImageField) {
                                                                <div class="field_pic"></div>
                                                            } else if (@item.FieldType == NodeEnums.BasicFieldType.MultiImage) {
                                                                <div class="field_pic"></div>
                                                                <div class="field_pic"></div>
                                                            } else if (item.FieldType == NodeEnums.BasicFieldType.SingleData) {
                                                                <span>数据源选择</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.BlockOnTop) {
                                                                <span>推荐到内容块</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.StatVisitInitial) {
                                                                <span>初始访问量</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Tag) {
                                                                <span>标签</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Seo) {
                                                                <span>内容SEO</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Relation) {
                                                                <span>内容相关</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Comment) {
                                                                <span>评论列表</span>
                                                            } else if (item.FieldType == NodeEnums.FunctionFieldType.Quiz) {
                                                                <span>题库</span>
                                                            } else if (extendField != null) {
                                                                @Html.Raw(CoralNodeContext.GetFieldHtml(extendField.Code, item))
                                                            } else {
                                                                <div class="field_editer">
                                                                    <div class="t"></div>
                                                                    <textarea readonly="readonly" class="h_8 w_37"></textarea>
                                                                </div>
                                                            }
                                                            @if (!string.IsNullOrEmpty(@item.Dataset)) {
                                                                <input name="fieldDomain" type="hidden" value='{"id":"@item.Id","refId":"@item.PrototypeId","page":"@group.Id","type":"@item.FieldType","remark":"@item.Title","name":"@item.FieldName","value":"@item.DefaultValue","tips":"@item.Hint","validate":"@item.Validator","entry":@item.Dataset,"unit":"@item.Measurement","filter":"@item.Filter"}' />} else {
                                                                <input name="fieldDomain" type="hidden" value='{"id":"@item.Id","refId":"@item.PrototypeId","page":"@group.Id","type":"@item.FieldType","remark":"@item.Title","name":"@item.FieldName","value":"@item.DefaultValue","unit":"@item.Measurement","tips":"@item.Hint","validate":"@item.Validator","filter":"@item.Filter"}' />
                                                            }
                                                            <textarea style="display: none" name="entry">@item.Dataset</textarea>
                                                        </td>
                                                    </tr>
                                                }
                                            </tbody>
                                        </table>
                                    </div>
                                }
                            </div>
                            <div class="fieldtype" id="addField">
                                <span class="mb_1" style="display: block">基本字段:</span>
                                <ul class="clearfix j_basic">
                                    @foreach (var item in fieldPlugins.Where(n => n.Type == PrototypeEnums.FieldPlugin.Basic)) {
                                        <li data-type="@item.Id">@item.Description</li>
                                    }
                                </ul>
                                <span class="mb_1" style="display: block">功能性字段:</span>
                                <ul class="clearfix j_ality">
                                    @foreach (var item in fieldPlugins.Where(n => n.Type == PrototypeEnums.FieldPlugin.Function)) {
                                        <li data-type="@item.Id">@item.Description</li>
                                    }
                                </ul>
                                @if (fieldPlugins.Count(n => n.Type == PrototypeEnums.FieldPlugin.Extend) > 0) {
                                    <span class="mb_1" style="display: block">扩展字段:</span>
                                    <ul class="clearfix j_extend_field">
                                        @foreach (var item in fieldPlugins.Where(n => n.Type == PrototypeEnums.FieldPlugin.Extend)) {
                                            <li data-type="@item.Id">@item.Description</li>
                                        }
                                    </ul>
                                }
                            </div>
                        </div>
                        <div id="fieldFrame">
                            <iframe name="fieldFrame" scrolling="auto" frameborder="0"></iframe>
                            <div id="fieldOpt">
                                <a class="ico ico_copy" title="复制"></a><a class="ico ico_del"
                                    action="/m/prototype/delField/" title="删除"></a>
                            </div>
                        </div>

                        <div class="fun p_2">
                            <input class="btn_1" type="submit" value="提交保存">
                        </div>
                    </div>
                    <a id="triggerValidate"></a>
                    <input type="hidden" name="prototypeId" value="@ViewBag.PrototypeId" id="refId" />

                </form>
            </div>
        </div>
    </div>
</div>
<!-- groupmanage -->
<div id="groupcontent">
    <ul class="list_tag d_GroupTabDialog " data-savehref="/m/prototype/saveFieldGroup"
        data-delhref="/m/prototype/delFieldGroup/" id="addTabDialog">
        @foreach (var item in @ViewBag.FieldGroupList) {
            <li><span>@item.Title</span><input type="text" data-groupid="@item.Id" value="@item.Title"><i
                class="del"></i>
            </li>
        }
        <li class="add"><a class="btn_4">添 加</a></li>
    </ul>
</div>
<script src="/Themes/CoralAdmin/_misc/scripts/addField.js"></script>
<script src="/Themes/FieldPlugin/addField.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.nav_left_style2').find('li').eq(0).addClass('current');
        $('form').submit(function () {
            var $textArea = $('textarea[name="entry"]');
            $textArea.each(function () {
                var $this = $(this);
                var field = JSON.parse($this.prev().val());
                if (field.entry == undefined) {
                    $this.val("");
                } else {
                    $this.val(JSON.stringify(field.entry));
                }
            });
        });
    })
</script>
